package chapters21;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by xinxuchu on 2020/2/25.
 */
public class Demo3 {

    public static void main(String[] args) throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
        //使用newInstance调用无参构造方法，创建对象
        List<String> list = ArrayList.class.newInstance();
        list.add("lalala");
        System.out.println(list.get(0));


        //使用Constructor获取指定构造器获取对象
        Constructor<StringBuilder> constructor = StringBuilder.class.getConstructor(new Class[]{int.class});
        StringBuilder sb = constructor.newInstance(100);
        sb.append("lalala22222");
        System.out.println(sb.toString());

        String.class.isAssignableFrom(String.class);
    }
}


